<?php

/* 品牌 brand */
class PriceModel extends BaseModel
{
    var $table  = 'price';
    var $prikey = 'price_id';
    var $_name  = 'price';

    /* 添加编辑时自动验证 */
    var $_autov = array(
        'price_name' => array(
            'required'  => true,    //必填
            'min'       => 1,       //最短1个字符
            'max'       => 100,     //最长100个字符
            'filter'    => 'trim',
        ),
        'sort_order'  => array(
            'filter'    => 'intval',
        )
    );

    /**
     *    删除商品品牌
     *
     *    @author    Hyber
     *    @param     string $conditions
     *    @param     string $fields
     *    @return    void
     */
    function drop($conditions, $fields = 'price_logo')
    {
        $droped_rows = parent::drop($conditions, $fields);
        if ($droped_rows)
        {
            restore_error_handler();
            $droped_data = $this->getDroppedData();
            foreach ($droped_data as $key => $value)
            {
                if ($value['price_logo'])
                {
                    @unlink(ROOT_PATH . '/' . $value['price_logo']);  //删除Logo文件
                }
            }
            reset_error_handler();
        }

        return $droped_rows;
    }

        /*
     * 判断名称是否唯一
     */
    function unique($price_name, $price_id = 0)
    {
        $conditions = "price_name = '" . $price_name . "' AND price_id != ".$price_id."";
        //dump($conditions);
        return count($this->find(array('conditions' => $conditions))) == 0;
    }

    /* 按标签分类取得所有的品牌   */

    function getAllBrands()
    {
        $sql = "SELECT group_concat(price_id) as price_ids,COUNT(*) as count,tag FROM {$this->table} WHERE if_show = 1 GROUP BY tag ORDER BY count DESC";
        return $this->db->getAll($sql);
    }

     /**
     * 取得店铺分类列表
     *
     * @param int $parent_id 大于等于0表示取某个店铺分类的下级店铺分类，小于0表示取所有店铺分类
     * @return array
     */
    function get_list($price="")
    {
             return $this->findprice($price);
    }
    function get_brand_list()
    {
             return $this->findbrand();
    }
    function get_modeltotal($param=array())
    {
    	     $total=$this->get_daototal($param);
             return $total;
    }
    function get_catemodeltotal($param=array())
    {
    	     $total=$this->get_catedaototal($param);
             return $total;
    }
    function get_goods_modeltotal($array=array()){
    	     $total=$this->get_goods_daototal($array);
             return $total;
    }
    function get_goods_modelKeywordName($array=array()){
    	     $total=$this->get_goods_daoKeywordName($array);
             return $total;
    }
    function get_store_modelKeywordName($array=array()){
    	     $total=$this->get_store_daoKeywordName($array);
             return $total;
    }
}

?>